#if UNITY_IOS
using IQIGame.Onigao.GameAOT;
using UnityEngine;

namespace IQIGame.USDK
{
    public class IQIUSDKImpl_iOS : MonoBehaviour, IQIUSDKInterface
    {
        public void init()
        {
            IOSInterface.iqi_usdk_initUSDK();
        }

        public void login()
        {
            IOSInterface.iqi_usdk_login();
        }

        public void logout()
        {
            IOSInterface.iqi_usdk_logout();
        }

        public void exit()
        {
            //empty
        }

        public void switchAccount()
        {
            IOSInterface.iqi_usdk_switch_account();
        }

        public bool isSupportExitDialog()
        {
            return false;
        }

        public bool isSupportSwitchAccount()
        {
            return IOSInterface.iqi_usdk_is_support_switch_account();
        }

        public void pay(PaymentParameters orderInfo, RoleInfo roleInfo)
        {
            var orderStr = JsonUtility.ToJson(orderInfo);
            var roleStr = JsonUtility.ToJson(roleInfo);
            IOSInterface.iqi_usdk_pay(orderStr, roleStr);

        }

        public void extraFunc(ExtraFuncType type, string jsonData)
        {
            IOSInterface.iqi_usdk_extraFunc((int)type, jsonData);
        }

        public void setAgreeProtocol()
        {
            //empty
        }


        public void enterGame(RoleInfo roleInfo)
        {
            var str = JsonUtility.ToJson(roleInfo);
            IOSInterface.iqi_usdk_report_role_info(3, str);
        }

        public void createNewRole(RoleInfo roleInfo)
        {
            var str = JsonUtility.ToJson(roleInfo);
            IOSInterface.iqi_usdk_report_role_info(2, str);
        }

        public void roleLevelUp(RoleInfo roleInfo)
        {
            var str = JsonUtility.ToJson(roleInfo);
            IOSInterface.iqi_usdk_report_role_info(4, str);
        }

        public void roleSelectServer(RoleInfo roleInfo)
        {
            var str = JsonUtility.ToJson(roleInfo);
            IOSInterface.iqi_usdk_report_role_info(1, str);
        }

        public void roleExitGame(RoleInfo roleInfo)
        {
            var str = JsonUtility.ToJson(roleInfo);
            IOSInterface.iqi_usdk_report_role_info(5, str);
        }

        public void roleReport(RoleInfo roleInfo)
        {
            var str = JsonUtility.ToJson(roleInfo);
            IOSInterface.iqi_usdk_report_role_info(0, str);
        }


        public int getChannelId()
        {
            return IOSInterface.iqi_usdk_getChannelId();
        }

        public string getChannelName()
        {
            return IOSInterface.iqi_usdk_getChannelName();
        }

        public int getImgId()
        {
            return 0;
        }

        public string getCpsId()
        {
            return "";
        }

        public string getChannelSDKVersion()
        {
            return IOSInterface.iqi_usdk_getChannelSDKVersion();
        }

        public string getUSDKVersion()
        {
            return IOSInterface.iqi_usdk_getUSDKVersion();
        }

        public string getCustomParams(string key)
        {
            return null;
        }

        public string getUniqueId()
        {
            return IOSInterface.iqi_usdk_getIDFV();
        }

        public string getTraceID()
        {
            return IOSInterface.iqi_usdk_getIDFA();
        }

        #region call back
        public void onInitSuccess(string none)
        {
            Debug.LogFormat("call event onInitSuccess");
            IQIUSDK.Instance.OnInitSuccess?.Invoke();
        }

        public void onInitFailed(string msg)
        {
            Debug.LogFormat("call event onInitFailed:{0}", msg);
            IQIUSDK.Instance.OnInitFailed?.Invoke(msg);
        }

        public void onLoginSuccess(string userJson)
        {
            Debug.LogFormat("call event onLoginSuccess:{0}", userJson);
            var userInfo = JsonUtility.FromJson<UserInfo>(userJson);
            IQIUSDK.Instance.OnLoginSuccess?.Invoke(userInfo);
        }

        public void onLoginFailed(string msg)
        {
            Debug.LogFormat("call event onLoginFailed:{0}", msg);
            IQIUSDK.Instance.OnLoginFailed?.Invoke(msg);
        }

        public void onLoginCancel(string none)
        {
            Debug.LogFormat("call event onLoginCancel:{0}", none);
            IQIUSDK.Instance.OnLoginCancel?.Invoke();
        }

        public void onSwitchAccountSuccess(string userJson)
        {
            Debug.LogFormat("call event onSwitchAccountSuccess:{0}", userJson);
            var userInfo = JsonUtility.FromJson<UserInfo>(userJson);
            IQIUSDK.Instance.OnSwitchSuccess?.Invoke(userInfo);
        }

        public void onSwitchAccountFailed(string msg)
        {
            Debug.LogFormat("call event onSwitchAccountFailed:{0}", msg);
            IQIUSDK.Instance.OnSwitchFailed?.Invoke(msg);
        }

        public void onSwitchAccountCancel(string none)
        {
            Debug.LogFormat("call event onSwitchAccountCancel:{0}", none);
            IQIUSDK.Instance.OnSwitchCancel?.Invoke();
        }

        public void onLogoutSuccess(string none)
        {
            Debug.LogFormat("call event onLogoutSuccess:{0}", none);
            IQIUSDK.Instance.OnLogoutSuccess?.Invoke();
        }

        public void onLogoutFailed(string msg)
        {
            Debug.LogFormat("call event onLogoutFailed:{0}", msg);
            IQIUSDK.Instance.OnLogoutFailed?.Invoke(msg);
        }

        public void onLogoutCancel(string none)
        {
            Debug.LogFormat("call event onLogoutCancel:{0}", none);
            IQIUSDK.Instance.OnLogoutCancel?.Invoke();
        }

        public void onPaySuccess(string payJsonData)
        {
            Debug.LogFormat("call event onPaySuccess:{0}", payJsonData);
            var payData = JsonUtility.FromJson<PayResultData>(payJsonData);
            IQIUSDK.Instance.OnPaySuccess?.Invoke(payData);
        }

        public void onPayFailed(string payJsonData)
        {
            Debug.LogFormat("call event onPayFailed:{0}", payJsonData);
            var payData = JsonUtility.FromJson<PayResultData>(payJsonData);
            IQIUSDK.Instance.OnPayFailed?.Invoke(payData);
        }

        public void onPayCancel(string payJsonData)
        {
            Debug.LogFormat("call event onPayCancel:{0}", payJsonData);
            var payData = JsonUtility.FromJson<PayResultData>(payJsonData);
            IQIUSDK.Instance.OnPayCancel?.Invoke(payData);
        }

        public void onExtraFuncSuccess(string jsonData)
        {
            Debug.LogFormat("call event onExtraFuncSuccess:{0}", jsonData);
            var data = JsonUtility.FromJson<ExtraFuncData>(jsonData);
            IQIUSDK.Instance.OnExtraFuncSuccess?.Invoke(data);
        }

        public void onExtraFuncFailed(string jsonData)
        {
            Debug.LogFormat("call event onExtraFuncFailed:{0}", jsonData);
            var data = JsonUtility.FromJson<ExtraFuncData>(jsonData);
            IQIUSDK.Instance.OnExtraFuncFailed?.Invoke(data);
        }

        #endregion


    }
}
#endif